/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.images;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Random;

/**
 * <p>Project: jse2204 - Img2
 * <p>Powered by webrx On 2022-09-26 09:31:17
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Img2 {
    public static void main(String[] args) throws Exception {
        //读取图像
        BufferedImage src = ImageIO.read(new File("c:/abc/g1.jpg"));
        int width = src.getWidth();
        int height = src.getHeight();

        //建立一个新图像 将颜色图像变为黑白（灰度）
        //BufferedImage dst = new BufferedImage(width,height,10);
        //Graphics2D g = dst.createGraphics();
        //g.drawImage(src,0,0,null);
        //g.dispose();

        //ImageIO.write(dst,"jpg",new File("c:/abc/g2.jpg"));

        //BufferedImage dst = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        //Graphics2D g = dst.createGraphics();

        Graphics2D g = src.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        //Color mc = Color.RED;
        //Color mc = new Color(255,0,0);
        //Color mc = new Color(0, 255, 0, 50);
        Color mc = new Color(0xff, 0x33, 0xff, 30);
        g.setColor(mc);

        g.fillRect(0, 0, width, height);

        Random rand = new Random();
        for (int i = 0; i < 260; i++) {
            g.setColor(new Color(255,255,255,35));
            int x = rand.nextInt(width);
            int y = rand.nextInt(height);
            g.fillOval(x, y, 25, 25);
        }
        g.dispose();
        ImageIO.write(src, "jpg", new File("c:/abc/g3.jpg"));

    }
}
